package view;

import controller.ModifyBookListener;
import pojo.Book;

import javax.swing.*;
import java.awt.*;

public class ModifyBook extends JDialog {
    private JLabel labelID,labelName,labelWriter,labelPage,labelPrice,labelPress,labelClassification,labelSurplus,labelTotal,labelLend;
    private JTextField tfID,tfName,tfWriter,tfPage,tfPrice,tfPress,tfClassification,tfSurplus,tfTotal,tfLend;
    private Book book;
    private ModifyBookListener modifyBookListener;
    private JComboBox cBType;
    private BookClassification bookClassification;
    public ModifyBook(Book book,BookClassification bookClassification){
        this.book=book;
        this.bookClassification=bookClassification;
        modifyBookListener=new ModifyBookListener(this,this.bookClassification);
        this.setTitle("图书信息");
        this.setSize(400, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
        this.add(this.getPanel(),BorderLayout.CENTER);
        this.add(this.getButton(),BorderLayout.SOUTH);
    }

    public JPanel getPanel(){
        JPanel jPanel=new JPanel();
        jPanel.setLayout(new GridLayout(9,2));
//        labelID=new JLabel("书号");
        labelName=new JLabel("                             书名:");
        labelWriter=new JLabel("                             作者:");
        labelPage=new JLabel("                             页码:");
        labelPrice=new JLabel("                             价格:");
        labelPress=new JLabel("                            出版社:");
        labelClassification=new JLabel("                             类别:");
        labelTotal=new JLabel("                             总数:");
        labelLend=new JLabel("                             借出:");
        labelSurplus=new JLabel("                             库存:");
//        tfID=new JTextField(book.getBookId(),15);
        tfName=new JTextField(book.getBookName(),15);
        tfWriter=new JTextField(book.getWriter(),15);
        tfPage=new JTextField(book.getPage(),15);
        tfPrice=new JTextField(book.getPrice(),15);
        tfPress=new JTextField(book.getPress(),15);
        cBType=new JComboBox();    //创建JComboBox
        cBType.addItem(book.getClassification());    //向下拉列表中添加一项
        cBType.addItem("马列主义毛泽东思想");
        cBType.addItem("哲学");
        cBType.addItem("社会科学");
        cBType.addItem("自然科学");
        cBType.addItem("综合性图书");
        tfTotal=new JTextField(book.getTotal());
        tfLend=new JTextField(book.getLend());
        tfSurplus=new JTextField(book.getSurplus(),15);

        jPanel.add(labelName);
        jPanel.add(tfName);

        jPanel.add(labelWriter);
        jPanel.add(tfWriter);

        jPanel.add(labelPage);
        jPanel.add(tfPage);

        jPanel.add(labelPrice);
        jPanel.add(tfPrice);

        jPanel.add(labelPress);
        jPanel.add(tfPress);

        jPanel.add(labelClassification);
        jPanel.add(cBType);

        jPanel.add(labelTotal);
        jPanel.add(tfTotal);

        jPanel.add(labelLend);
        jPanel.add(tfLend);

        jPanel.add(labelSurplus);
        jPanel.add(tfSurplus);

        return jPanel;
    }
    public JPanel getButton(){
        JButton jButton=new JButton("修改");
        JButton jButton1=new JButton("删除");
        JButton jButton2=new JButton("返回");
        jButton.addActionListener(modifyBookListener);
        jButton1.addActionListener(modifyBookListener);
        jButton2.addActionListener(modifyBookListener);
        JPanel jPanel=new JPanel();
        jPanel.add(jButton);
        jPanel.add(jButton1);
        jPanel.add(jButton2);
        return jPanel;
    }

    public Book getBook() {
        return book;
    }

    public JLabel getLabelID() {
        return labelID;
    }

    public JTextField getTfName() {
        return tfName;
    }

    public JTextField getTfWriter() {
        return tfWriter;
    }

    public JTextField getTfPage() {
        return tfPage;
    }

    public JTextField getTfPrice() {
        return tfPrice;
    }

    public JTextField getTfPress() {
        return tfPress;
    }

    public JTextField getTfClassification() {
        return tfClassification;
    }

    public JTextField getTfSurplus() {
        return tfSurplus;
    }

    public JLabel getLabelName() {
        return labelName;
    }

    public JTextField getTfID() {
        return tfID;
    }

    public JTextField getTfTotal() {
        return tfTotal;
    }

    public JTextField getTfLend() {
        return tfLend;
    }

    public JComboBox getCBType() {
        return cBType;
    }
}
